/*
 * =====================================================================================
 *
 *       Filename:  funNumSys_1023.cc
 *
 *    Description:  abosolutely no searching sulution, so look into the binary format of the demanded integer
 *
 *        Version:  1.0
 *
 *        Created:  09/20/2012 01:35:38 AM
 * =====================================================================================
 */
#include	<stdio.h>
#include	<string.h>
#include	<limits.h>
#include    <iostream>

typedef long long ll;
typedef unsigned long long ull;

char sign[64];
int  mark[64] = {0x00};
__int64 value;
int K;

int findPositiveNum(__int64 v)
{
    memset(mark, 0x00, sizeof(mark));
    int jj = 0;
    __int64 base = 1;
    for (int i = 0; i < K; ++i) {
        if (v & (base << i)) {
            for (jj = i; jj < K; ++jj) {
                if (mark[jj] == 1) {
                    mark[jj] = 0;
                    if (sign[jj] == -1)
                        break;
                } else {
                    mark[jj] = 1;
                    if (sign[jj] == 1)
                        break;
                }
            } // loop
            if (jj >= K)
                return 0;
        } // if bit set
    } // iterate for
    return 1;
}

int main(int argc, char *argv[])
{
    int T;
    char str[66];
    __int64   maxvalue, minvalue;
    __int64   posValue;

    while (scanf("%d", &T) == 1)
    {
        while(T--) {
            scanf("%d%s%I64d", &K, str, &value);
            maxvalue = 0; minvalue = 0;
            for (int i = 0; i < K; ++i)
            {
                maxvalue <<= 1;
                minvalue <<= 1;
                if (str[i] == 'p') {
                    maxvalue += 1;
                    sign[K-i-1] = 1;
                }
                else  {
                    sign[K-i-1] = -1;
                    minvalue += 1;
                }
            }
            if (value < 0)
                posValue = -value;
            else 
                posValue = value;
            //if ((value > 0 && posValue > maxvalue) || (value < 0 && posValue>minvalue && posValue <= LLONG_MAX))
                //printf ( "Impossible\n" );
            //else {
                if (value < 0) {
                    for (int i = 0; i < K; ++i)
                        sign[i] = -sign[i];
                }
                int res = findPositiveNum(posValue);
                if (res) {
                    for(int j = K-1; j >= 0; --j) 
                        printf ( "%d", mark[j]);
                    printf ( "\n" );
                } else 
                    printf ( "Impossible\n" );
           // }

        }
    }
    return 0;
}
